package com.we.connect.weconnect.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.we.connect.weconnect.mapper.system.SysInfoMapper;
import com.we.connect.weconnect.model.system.SysInfo;
import com.we.connect.weconnect.model.system.SysUser;
import com.we.connect.weconnect.service.SysInfoService;
import com.we.connect.weconnect.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysInfoServiceImpl implements SysInfoService {

    @Autowired
    private SysInfoMapper sysInfoMapper;

    @Override
    public Boolean addSysInfo(SysInfo sysInfo) {
        QueryWrapper<SysInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", sysInfo.getUserId());
        SysInfo info = sysInfoMapper.selectOne(wrapper);

        int i;
        if(null != info){
            i = sysInfoMapper.update(sysInfo, wrapper);
        }else {

            i = sysInfoMapper.insert(sysInfo);
        }

        if(i != 1){
            return false;
        }

        return true;
    }

    @Override
    public SysInfo findSysInfo(Long user_id) {
        QueryWrapper<SysInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", user_id);
        return sysInfoMapper.selectOne(wrapper);
    }
}
